package com.ea.eadp.nexus.test.pageDefinition.mobile;

import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;


public class UpgradePage extends MobileBasePage {
    public final static String upgradePage = "upgradePage";
    public static final String originIdInputBox = "upgrade-originId";

    public UpgradePage(WebDriver driver) {
        super(driver, UpgradePage.class, upgradePage);
    }

    public void enterOriginId(String originId) {
        log.info("Enter Origin Id:" + originId);
        sendInput(originIdInputBox, originId);
        driver.findElement(By.xpath("//form[@id='upgradeForm']/div[2]/div[1]/input")).click();
    }

    public void validateOriginId(String originId, String errorMessage) {
        log.info("Validate Origin Id:" + originId);
        sendInput(originIdInputBox, originId);
        driver.findElement(By.xpath("//form[@id='upgradeForm']/div[2]/div[1]/input")).click();
        TestUtil.sleep(1);
        Assert.assertEquals(getOriginIdInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public String getOriginIdInvalidError() {
        return getElementStringByXPath("//form[@id='upgradeForm']/div[1]/div/span[2]");
    }

    public String getResetResponse() {
        TestUtil.sleep(1);
        return getElementStringByXPath("//div[@id='reset-popup']/div[2]/div[1]");
    }
}
